package com.mark.controller.backend;

import com.mark.common.ServerResponse;
import com.mark.controller.common.CurrentUser;
import com.mark.pojo.Admin;
import com.mark.service.IAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Created by Choisaaaa on 2018/5/8.
 * 管理员模块的控制器
 */
@Controller
@RequestMapping("/manage/admin/")
public class AdminManageController {
    @Autowired
    private IAdminService iAdminService;

    //1.管理员登录
    @RequestMapping(value = "login.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse login(HttpSession session,String adminName,String password, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse){
        ServerResponse response = iAdminService.login(adminName,password);
        if(response.isSuccess()){
            Admin  admin = (Admin) response.getData();
            CurrentUser.setCurrentAdmin(httpServletRequest,httpServletResponse,session.getId(),admin);
        }
        return response;
    }
}

